<?php
//捐赠管理
namespace app\admin\controller;
use think\Db;
 class Donation extends Base {


     public function index(){
         if(request()->isAjax()){
             extract(input());
             $map =array();
             $page = input('page') ? input('page'):1;
             $limit = input("limit")?input("limit"):10;// 获取总条数;
             if(isset($key)&&$key!="")
             {
                 $map['a.donate_number'] = ['like',"%" . $key . "%"];
             }
             if(isset($start)&&$start!=""&&isset($end)&&$end=="")
             {
                 $map['a.pay_time'] = ['>= time',$start];
             }
             if(isset($end)&&$end!=""&&isset($start)&&$start=="")
             {
                 $map['a.pay_time'] = ['<= time',$end];
             }
             if(isset($start)&&$start!=""&&isset($end)&&$end!="")
             {
                 $map['a.pay_time'] = ['between time',[$start,$end]];
             }
             $map['a.cate']  = 1;
             $map['a.donate_status']  = 1;
             $count = Db::table('up_activity_order')->alias('a')
                 ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                 ->join('up_institutional_activities uia','uia.id = a.activity_id','left')
                 ->join('up_mechanism um','um.mechanism_id = uia.activity_mechanism_id','left')
                 ->where($map)
                 ->count();
             $list = Db::table('up_activity_order')->alias('a')
                 ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                 ->join('up_institutional_activities uia','uia.id = a.activity_id','left')
                 ->join('up_mechanism um','um.mechanism_id = uia.activity_mechanism_id','left')
                 ->where($map)
                 ->field('a.*,uuu.user_username,uia.activity_name,um.mechanism_name')
                 ->order('a.pay_time desc')
                 ->page($page, $limit)
                 ->select();//计算总页面
             return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$list]);

         }

         return $this->fetch();
     }
 }